package com.leave.web.filter;

import jakarta.servlet.*;
import jakarta.servlet.annotation.*;

import java.io.IOException;

/**
 * 字符编码过滤器
 * @author amu_1115@126.com
 * @version 1.0
 */
@WebFilter(filterName = "CharacterEncodingFilter",urlPatterns = {"/*"})
public class CharacterEncodingFilter implements Filter {
    private final static String ENCODE="UTF-8";
    @Override
    public void init(FilterConfig config) throws ServletException {
    }
    @Override
    public void destroy() {
    }
    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException {
        //请求编码默认设置为utf-8
        request.setCharacterEncoding(ENCODE);
        response.setCharacterEncoding(ENCODE);
        chain.doFilter(request, response);
    }
}
